package com.servlet;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ErrorDeal
 */
@WebServlet("/files/ErrorDeal")
public class ErrorDeal extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ErrorDeal() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String errorCode = request.getParameter("error");
		String message = null;
		String jump = null;
		if (errorCode!=null)
			switch(errorCode){
			case "GU" : message = "请登陆后操作"; jump = "login.jsp"; break;
			case "GA" : message = "无足够权限"; jump = "index.jsp"; break;
			case "GI" : message = "登陆认证失败"; jump = "login.jsp"; break;
			case "GO" : message = "登出失败"; jump = "index.jsp"; break;
			case "GP" : message = "密码修改失败"; jump = "UserPas.jsp"; break;
			case "GE" : message = "信息修改失败"; jump = "UserMes.jsp"; break;
			case "CVH" : message = "查询失败"; jump = "list_CLCX.jsp"; break;
			case "CVE" : message = "查询失败"; jump = "list_CLCX.jsp"; break;
			case "CVC" : message = "查询失败"; jump = ""; break;
			case "CVB" : message = "查询失败"; jump = "list_CLHC.jsp"; break;
			case "CD" : message = "车辆删除失败"; jump = "list_CLCX.jsp"; break;
			case "CA" : message = "车辆添加失败"; jump = "CL_TJ.jsp"; break;
			case "CE" : message = "车辆编辑失败"; jump = "CL_BJ.jsp?lpn="+request.getParameter("lpn"); break;
			case "CC" : message = "车辆出车失败"; jump = "list_CLSQ.jsp?lpn="+request.getParameter("lpn"); break;
			case "CB" : message = "车辆回车失败"; jump = "list_CLHC.jsp"; break;
			case "CMI" : message = "车辆导入失败"; jump = "list_CLCX.jsp"; break;
			case "CMO" : message = "车辆导出失败"; jump = "list_CLCX.jsp"; break;
			case "CQ" : message = "车辆ID不存在"; jump = "list_CLCX.jsp"; break;
			case "IVH" : message = "查询失败"; jump = "listWP.jsp"; break;
			case "IVE" : message = "查询失败"; jump = "listWP.jsp"; break;
			case "IVA" : message = "查询失败"; jump = ""; break;
			case "IVT" : message = "查询失败"; jump = ""; break;
			case "IE" : message = "物品编辑失败"; jump = "WP_BJ.jsp?iid="+request.getParameter("iid"); break;
			case "II" : message = "物品入库失败"; jump = "WP_In.jsp?iid="+request.getParameter("iid"); break;
			case "IO" : message = "物品出库失败"; jump = "WP_Out.jsp?iid="+request.getParameter("iid"); break;
			case "IMI" : message = "物品导入失败"; jump = "listWP.jsp"; break;
			case "IMO" : message = "物品导出失败"; jump = "listWP.jsp"; break;
			case "IQ" : message = "物品ID不存在"; jump = "listWP.jsp"; break;
			case "ISV" : message = "查询失败"; jump = "WP_Storage.jsp"; break;
			case "ISA" : message = "添加仓库失败"; jump = "storeAdd.jsp"; break;
			case "ISD" : message = "删除仓库失败"; jump = "WP_Storage.jsp"; break;
			case "ISE" : message = "编辑仓库失败"; jump = "Storage_BJ.jsp?store="+request.getParameter("store"); break;
			case "ISQ" : message = "仓库ID不存在"; jump = "WP_Storage.jsp"; break;
			case "DVH" : message = "查询失败"; jump = "listSB.jsp"; break;
			case "DVE" : message = "查询失败"; jump = "listSB.jsp"; break;
			case "DVA" : message = "查询失败"; jump = "listSB.jsp"; break;
			case "DVT" : message = "查询失败"; jump = "listSB.jsp"; break;
			case "DD" : message = "设备删除失败"; jump = "listSB.jsp"; break;
			case "DA" : message = "设备添加失败"; jump = "SB_TJ.jsp"; break;
			case "DE" : message = "设备编辑失败"; jump = "SB_BJ.jsp?devids="+request.getParameter("devids"); break;
			case "DT" : message = "设备转移失败"; jump = "SB_ZY.jsp?devids="+request.getParameter("devids"); break;
			case "DSS" : message = "设备报废失败"; jump = "listSB.jsp"; break;
			case "DSV" : message = "查询失败"; jump = "listSB.jsp"; break;
			case "DSC" : message = "报废取消失败"; jump = "SB_BF.jsp"; break;
			case "DMI" : message = "设备导入失败"; jump = "listSB.jsp"; break;
			case "DMO" : message = "设备导出失败"; jump = "listSB.jsp"; break;
			case "DQ" : message = "设备ID不存在"; jump = "listSB.jsp"; break;
			case "MVH" : message = "查询失败"; jump = "RL.jsp"; break;
			case "MVD" : message = "查询失败"; jump = "RL.jsp"; break;
			case "MD" : message = "预约失败"; jump = "meetBooking.jsp?date="+request.getParameter("date"); break;
			case "MMVH" : message = "查询失败"; jump = "meetingRoom.jsp"; break;
			case "MMVE" : message = "查询失败"; jump = "meetingRoom.jsp"; break;
			case "MMA" : message = "预约同意失败"; jump = "meetingRoom.jsp"; break;
			case "MMR" : message = "预约拒绝失败"; jump = "meetingRoom.jsp"; break;
			case "MMD" : message = "预约删除失败"; jump = "meetingRoom.jsp"; break;
			case "UV" : message = "查询失败"; jump = "User.jsp"; break;
			case "UA" : message = "用户添加失败"; jump = "User_Add.jsp"; break;
			case "UD" : message = "用户删除失败"; jump = "User.jsp"; break;
			case "UE" : message = "用户编辑失败"; jump = "User_BJ.jsp?userNumber="+request.getParameter("userNumber"); break;
			default : message = "未知错误"; jump = "index.jsp";break;
			}
		response.sendRedirect("error.jsp?message="+URLEncoder.encode(message,"UTF-8")+"&jump="+jump);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
